
$(document).ready(function() {	
	//伸缩导航栏
	$yq = $("div.lefttitle");
	$yq.attr("style","background-color:#c7c7c7;");
	$yq.click(function() {
		var index = $yq.index(this);
		$("div.leftsmalltitle").eq(index).slideToggle(250);
	});
	$yq.mousemove(function() {
		$(this).attr("style","background-color:#a7a7a7;");
	});
	$yq.mouseout(function() {
		$(this).attr("style","background-color:#c7c7c7;");
	});
	
	//表单色差
	$("table.tb tr:odd").attr("bgcolor","#ffffff");
	$("table.tb tr:even").attr("bgcolor","#f7f7f7");
	$("table.tblist tr:first").attr("bgcolor","#9db8e3");
	$("table.tb tr:last").attr("bgcolor","#9db8e3");
//	//列表色差
	$("table.tblist tr:odd").attr("bgcolor","#ffffff");
	$("table.tblist tr:even").attr("bgcolor","#f7f7f7");
//	$("table.tblist tr:first").eq(1).attr("bgcolor","#9db8e3");	
//	$("table.tblist tr:last").attr("bgcolor","#9db8e3");
	
});

function init(val1, val2) {
	document.getElementById("province").options.add(new Option("1", "1"));
	document.getElementById("city").options.add(new Option("1", "1"));
}
//确定提交
function submitConfirm() {
	if(confirm("请问您确定要提交吗？"))
		return true;
	else 
		return false;
}
//确定重置
function resetConfirm() {
	if(confirm("重置将丢失您的修改，请问确定要重置吗？"))
		return true;
	else 
		return false;
}//确定删除
function deleteConfirm() {
	if(confirm("请问您确定要删除该条记录吗？"))
		return true;
	else 
		return false;
}
//返回
function back() {
	if(confirm("返回将丢失您的修改，请问确定要返回吗？"))
		window.history.back(-1);
	else 
		return false;
}

function gotoEdit(currentTitle, currentPage){
	tipsWindown(currentTitle,"url:get?/refer/queryRefer.do?currentPage="+currentPage,"640","400","true","","true","text");
	return false;
}
function gotoEdit1(currentTitle, currentPage, index){
	tipsWindown(currentTitle,"url:get?/refer/queryRefer.do?currentPage="+currentPage+"&index="+index,"640","400","true","","true","text");
	return false;
}

function error(id, msg) {
    showMsg(validation[id].errorContainer(), "tishierror", msg);
}
function ok(id) {
	validation[id].errorContainer().next().hide();
}
 
function showMsg(p, cls, msg) {
     var tip = p.next(".tishi,.tishierror,.tishisuc").toArray();
    if (tip.length == 0) {
        tip = $("<div/>").insertAfter(p).toArray();
    }
 
    $(tip[0]).attr({"class":cls}).html(msg);
}

function required(elId) {
	
    if ($("#" + elId).is("input")) {
        var value = $("#" + elId).val();
        var len = $.trim(value).length;
        if (len == 0) {
			error(elId, "此项为必填项");
            return false;
        }
    }
    return true;
}
var validation = {
	    textfield:{
			 errorContainer:function() {
	            return $("#textfield").parents(".reg_m_list");
	        },
	        validate:function(elId) {
	            if (!required(elId)) {
					
	            	return false;
	            }
	            return true;
	        },
	    },
	     textfield2:{
			 errorContainer:function() {
	            return $("#textfield2").parents(".reg_m_list");
	        },
	        validate:function(elId) {
	            if (!required(elId)) {
					
	            	return false;
	            }
	            return true;
	        },
	    },
		 textfield3:{
			 errorContainer:function() {
	            return $("#textfield3").parents(".reg_m_list");
	        },
	        validate:function(elId) {
	            if (!required(elId)) {
					
	            	return false;
	            }
	            return true;
	        },
	    }
	    
	};

$().ready(function() {
	  $("#loginform").submit(function() {
		  
		 var result=true;
	        var errorId=false;
	        for (var id in validation) {
	            if (!validation[id].validate(id)) {
	                !errorId?errorId=id:"";
	                result=false;
	            }else{
					ok(id);
					}
	        }
	    	
	        if(!result){
	            if($("#"+errorId).length!=0){
	                $(window).scrollTop($("#"+errorId).position().top);
	            }

	            return false;
	        }
	    
	        return true;
	    });
$("#loginbu").click(function() {
	$("#loginform").submit();
    
});

 
$(document).bind('keydown',function(event){
	if(event.keyCode==13){
		$("#loginform").submit();
	}
});

});





